home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 4
/
Aminet 4 - November 1994.iso
/
aminet
/
dev
/
amos
/
amosl0794.lzh
/
AMOSLIST
/
000087_mentat@sefl.satelnet.org_Sat Jul 23 15:21:43 1994.msg
< prev
next >
Wrap
Internet Message Format
|
1994-08-01
|
3KB
Received: from sefl.satelnet.org (satelnet.org) by nfs1.digex.net with SMTP id AA20704
(5.67b8/IDA-1.5 for <mcox@access.digex.net>); Sat, 23 Jul 1994 15:21:38 -0400
Received: (from mentat@localhost) by sefl.satelnet.org (8.6.8.1/8.6.6) id PAA29227; Sat, 23 Jul 1994 15:21:21 -0400
From: MenTaT - !Productions <mentat@sefl.satelnet.org>
Message-Id: <199407231921.PAA29227@sefl.satelnet.org>
Subject: Re: PIPEing
To: mcox@access.digex.net (M D Cox)
Date: Sat, 23 Jul 1994 15:21:19 -0400 (EDT)
Cc: amos-list@access.digex.net
In-Reply-To: <199407231643.AA22497@access1.digex.net> from "M D Cox" at Jul 23, 94 12:43:33 pm
Content-Type: text
Content-Length: 1944
Status: RO
>
> Has anyone ever written a program to accept STDIN or piping? For
> instance, if I wrote a program called WC that would count the number of words
> and lines in a text file, would I be able to:
>
> type textfile.txt > WC
>
> or
>
> type textfile.txt | WC
I'm not sure how the shell handles pipes - the easiest way to test it
would be to try it!
> I know i can do: WC textfile.txt, but then could I do:
>
> WC textfile.txt > result.txt
Only if WC directed its output to the current shell window, which under
AMOS is hard to do. You could be sneaky, and use a different
metacharacter, maybe @ or something else that isn't used, and get the
AMOS program to redirect it, but it's not a very good solution... For
this kind of thing you're better off using C.
> with result.txt being created and containing the output of WC?
>
> If anyone is familiar with programs like AWK or GREP, help me out if you
> can, please! :)
Here's a nice awk program... (Dunno if it works in GNU awk, but it works
in System V...)
awk '
FILENAME != prevfile { # new file
NR = 1 # reset line number
prevfile = FILENAME
}
NF > 0 {
if ($1 == lastword)
printf "double %s, file %s, line %d\n",$1,FILENAME,NR
for (i = 2; i <= NF; i++)
if ($i == $(i-1))
printf "double %s, file %s, line %d\n",$i,FILENAME,NR
if (NF > 0)
lastword = $NF
}' $*
It looks for pairs of identical adjacent words... Kinda nifty. :) (And
you can pipe it. Not that this helps you at all. :)
I don't think AMOS was really ever designed for running from a shell, so
while there probably IS a way of piping and redirecting input and output,
C would be a lot easier. (What am I saying? C EASY? :)
Any awk/grep questions, just ask! :) (And here's something nice - search
for users with no password an a *NIX machine :
grep '^[^:]*::' /etc/passwd
Not that I condone this sort of activity... :)